package com.itheima.mall.controller;

import com.itheima.mall.dto.CouponDto;
import com.itheima.mall.pojo.Coupon;
import com.itheima.mall.service.SmsCouponService;
import com.itheima.mall.vo.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/coupon")
public class SmsCouponController {


    @Autowired
    private SmsCouponService smsCouponService;


    /**
     * 添加优惠券 TODO 这个地方sql语句没写完
     */
    @PostMapping("/create")
    public ResponseEntity<String> create(@RequestBody CouponDto couponParam){
        log.info("couponParam: {}",couponParam);

        smsCouponService.create(couponParam);
        return ResponseEntity.ok("ok");
    }

    /**
     * 删除优惠券
     */
    @PostMapping("/delete/{id}")
    public ResponseEntity<String> delete(@PathVariable Long id){
        log.info("id: {}",id);
        smsCouponService.delete(id);
        return ResponseEntity.ok("ok");
    }

    /**
     * 根据优惠券名称和类型分页获取优惠券列表
     */
    @GetMapping("/list")
    public ResponseEntity<PageResult> list(String name,Integer pageNum,Integer pageSize,Integer type){
        PageResult pageResult = smsCouponService.list(name,pageNum,pageSize,type);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 修改优惠券
     */
    @PostMapping("/update/{id}")
    public ResponseEntity<String> update(@RequestBody CouponDto couponParam,@PathVariable Long id){
        log.info("couponParam: {}",couponParam);
        smsCouponService.update(couponParam,id);
        return ResponseEntity.ok("ok");
    }

    /**
     * 获取单个优惠券的详细信息
     */
    @GetMapping("/{id}")
    public ResponseEntity<CouponDto> coupon(@PathVariable Long id){
        CouponDto couponDto = smsCouponService.coupon(id);
        return ResponseEntity.ok(couponDto);
    }


}
